import { Repository, Autowired } from "boot/decorator"
import { CurdTemplate } from "boot/db"

let ii = 1
@Repository()
export default class UserDao {

  @Autowired()
  curdTemplate: CurdTemplate

  // async addUser(userInfo: IUserInfo) {
  //   return userInfo
  // }

  async getUserById(id: number) {
    // language=MySQL
    const sql = `SELECT * FROM users WHERE id = 1`
    const [rows, fields] = await this.curdTemplate.query(`SELECT * FROM users WHERE id = 1`)
    console.log(rows)
    return rows
  }

  async addUser() {
    const id = Date.now() % 100000000
    const res = await this.curdTemplate.execute(`insert into users values(${id + ii++},'${id}',CURRENT_TIMESTAMP,1)`)
    return res
  }
}
